
module.exports = {
    /**
     * 随机整数
     */
    random(min, max) {
        if (max == null) {
            max = min;
            min = 0;
        }

        return min + Math.floor(Math.random() * (max - min + 1));
    },

    loadPrefabFile(path, callback) {
        cc.loader.loadRes(path, (err, prefab) => {
            if (err) {
                cc.error(`Load prefab error: ${err}`);
                return;
            }

            let newPrefab = cc.instantiate(prefab);
            callback(newPrefab);
        });
    },


    showBorder: function (node, color = cc.Color.BLACK, gNode) {
        let box = node instanceof cc.Rect ? node : node.getBoundingBoxToWorld();

        gNode = gNode || cc.director.getScene().children[0];

        let ctx = gNode.getComponent(cc.Graphics) || gNode.addComponent(cc.Graphics);
        ctx.rect(box.x, box.y, box.width, box.height);

        if (color instanceof cc.Color) {
            ctx.strokeColor = color;
            ctx.lineWidth = 3;
        } else {
            ctx.strokeColor = color.color;
            ctx.lineWidth = color.width;
        }

        ctx.stroke();
    }
};
